<?php
namespace app\api\model\v1;

/*
 * content : 用户权限管理类
 * Author  : Songyicong
 * time    : 2018-04-19 10:41:29
 * email   : m13726262373@163.com
 */

use app\api\model\BaseModel;

class AdminAuth extends BaseModel{

    protected $table = "km_admin_auth";

    /** 查找当前是否存在,存在返回权限值,否则返回false */
    public function isAccessToken($access_token = ""){
        if(empty($access_token)){
            return null;
        }
        $auth_name = self::where('access_token',$access_token)->find();
        return empty($auth_name)?$auth_name:$auth_name->toArray();
    }

    /** 当前admin_id是否具有access_token */
    public static function isAdminId($admin_id = ""){
        if(empty($admin_id)){
            return false;
        }
        $results = self::field(['id'])->where('admin_id',$admin_id)->find();
        return empty($results)?false:$results->toArray();
    }

    /** 判断refer_token 是否存在 */
    public static function isReferToken($refer_token = ""){
        if(empty($refer_token)){
            return false;
        }
        $results = self::where('refresh_token',$refer_token)->find();
        return empty($results)?false:$results->toArray();
    }

}
